Here's the complete HTML code for a modern, visually appealing Redis documentation page:

```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis 完全指南 | 高性能键值数据库</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .hero {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
            color: white;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .feature-icon {
            font-size: 2.5rem;
            color: #4f46e5;
        }
        .section-title {
            position: relative;
            padding-bottom: 1rem;
        }
        .section-title:after {
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            width: 60px;
            height: 4px;
            background: #4f46e5;
            border-radius: 2px;
        }
        .code-block {
            background-color: #1e293b;
            color: #e2e8f0;
            border-radius: 0.5rem;
            font-family: 'Courier New', Courier, monospace;
        }
        .nav-link {
            transition: all 0.2s ease;
            position: relative;
        }
        .nav-link:hover {
            color: #4f46e5;
        }
        .nav-link:after {
            content: "";
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 0;
            height: 2px;
            background: #4f46e5;
            transition: width 0.3s ease;
        }
        .nav-link:hover:after {
            width: 100%;
        }
        .active-nav {
            color: #4f46e5;
            font-weight: 500;
        }
        .active-nav:after {
            width: 100%;
        }
        .command {
            background-color: #f1f5f9;
            border-left: 4px solid #4f46e5;
        }
        .command-title {
            background-color: #e2e8f0;
        }
        .data-structure {
            background: linear-gradient(to right, #f0fdf4, #ecfdf5);
            border-left: 4px solid #10b981;
        }
    </style>
</head>
<body class="antialiased">
    <div class="min-h-screen">
        <!-- Hero Section -->
        <div class="hero py-20 px-4 sm:px-6 lg:px-8">
            <div class="max-w-7xl mx-auto">
                <div class="flex flex-col md:flex-row items-center justify-between">
                    <div class="md:w-1/2 mb-10 md:mb-0">
                        <h1 class="text-4xl md:text-5xl font-bold mb-6">Redis 完全指南</h1>
                        <p class="text-xl mb-8 opacity-90">高性能键值数据库的全面解析与实践</p>
                        <div class="flex items-center space-x-4">
                            <span class="inline-flex items-center px-3 py-1 rounded-full bg-white bg-opacity-20 text-sm">
                                <i class="fas fa-bolt mr-2 text-yellow-300"></i> 10万/秒读写
                            </span>
                            <span class="inline-flex items-center px-3 py-1 rounded-full bg-white bg-opacity-20 text-sm">
                                <i class="fas fa-server mr-2 text-green-300"></i> 内存数据库
                            </span>
                        </div>
                    </div>
                    <div class="md:w-1/2 flex justify-center">
                        <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1652597734608-38890621-5542-4f06-9ac9-204a91542c92.png" alt="Redis Logo" class="w-64 h-64 object-contain">
                    </div>
                </div>
            </div>
        </div>

        <!-- Main Content -->
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
            <div class="flex flex-col lg:flex-row gap-8">
                <!-- Sidebar Navigation -->
                <div class="lg:w-1/4">
                    <div class="bg-white rounded-xl shadow-md p-6 sticky top-8">
                        <h3 class="text-lg font-semibold mb-4 text-slate-800">目录导航</h3>
                        <ul class="space-y-3">
                            <li><a href="#section1" class="nav-link active-nav">Redis简介</a></li>
                            <li><a href="#section2" class="nav-link">应用场景</a></li>
                            <li><a href="#section3" class="nav-link">环境搭建</a></li>
                            <li><a href="#section4" class="nav-link">服务启动</a></li>
                            <li><a href="#section5" class="nav-link">Redis客户端</a></li>
                            <li><a href="#section6" class="nav-link">解除本地绑定</a></li>
                            <li><a href="#section7" class="nav-link">安全加固</a></li>
                            <li><a href="#section8" class="nav-link">Java连接Redis</a></li>
                            <li><a href="#section9" class="nav-link">Spring操作Redis</a></li>
                            <li><a href="#section12" class="nav-link">事务管理</a></li>
                            <li><a href="#section17" class="nav-link">持久化机制</a></li>
                            <li><a href="#section18" class="nav-link">内存管理</a></li>
                        </ul>
                    </div>
                </div>

                <!-- Content Area -->
                <div class="lg:w-3/4">
                    <!-- Section 1: Redis简介 -->
                    <section id="section1" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">1. Redis简介</h2>
                        
                        <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <i class="fas fa-info-circle feature-icon mr-3"></i>
                                    <h3 class="text-xl font-semibold">什么是Redis?</h3>
                                </div>
                                <p class="mb-4">Redis是一种基于<strong class="text-blue-600">键值对</strong>的<strong class="text-blue-600">NoSQL</strong>数据库，与很多键值对数据库不同的是，Redis中的值可以是多种数据结构：</p>
                                
                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
                                    <div class="data-structure p-4 rounded-lg">
                                        <h4 class="font-medium mb-2 text-emerald-700">支持的数据结构</h4>
                                        <ul class="list-disc pl-5 space-y-1">
                                            <li>String (字符串)</li>
                                            <li>Hash (哈希)</li>
                                            <li>List (列表)</li>
                                            <li>Set (集合)</li>
                                            <li>Zset (有序集合)</li>
                                        </ul>
                                    </div>
                                    <div class="bg-blue-50 p-4 rounded-lg border-l-4 border-blue-500">
                                        <h4 class="font-medium mb-2 text-blue-700">主要特性</h4>
                                        <ul class="list-disc pl-5 space-y-1">
                                            <li class="text-red-600 font-medium">高性能：内存存储，10万/秒读写</li>
                                            <li class="text-red-600 font-medium">可靠性：数据持久化到硬盘</li>
                                            <li>支持多种编程语言API</li>
                                            <li>丰富的功能：事务、发布订阅等</li>
                                        </ul>
                                    </div>
                                </div>
                                
                                <div class="bg-slate-50 p-4 rounded-lg mb-6">
                                    <h4 class="font-medium mb-2 flex items-center">
                                        <i class="fas fa-quote-left text-gray-400 mr-2"></i>
                                        <span>来自百度百科的介绍</span>
                                    </h4>
                                    <p class="text-gray-700">Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库，并提供多种语言的API。从2010年3月15日起，Redis的开发工作由VMware主持。从2013年5月开始，Redis的开发由Pivotal赞助。</p>
                                </div>
                                
                                <div>
                                    <h4 class="font-medium mb-2">知名使用公司</h4>
                                    <div class="flex flex-wrap gap-3">
                                        <span class="bg-gray-100 px-3 py-1 rounded-full text-sm">新浪微博</span>
                                        <span class="bg-gray-100 px-3 py-1 rounded-full text-sm">阿里巴巴</span>
                                        <span class="bg-gray-100 px-3 py-1 rounded-full text-sm">腾讯</span>
                                        <span class="bg-gray-100 px-3 py-1 rounded-full text-sm">百度</span>
                                        <span class="bg-gray-100 px-3 py-1 rounded-full text-sm">搜狐</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 2: 应用场景 -->
                    <section id="section2" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">2. 应用场景</h2>
                        
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                                <div class="p-6">
                                    <div class="flex items-center mb-3">
                                        <i class="fas fa-database text-purple-500 mr-3 text-xl"></i>
                                        <h3 class="text-xl font-semibold">缓存</h3>
                                    </div>
                                    <p>几乎所有的大型网站都会使用到缓存，合理使用缓存可以加快网站响应速度，而且可以减少对数据库的访问压力。</p>
                                </div>
                            </div>
                            
                            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                                <div class="p-6">
                                    <div class="flex items-center mb-3">
                                        <i class="fas fa-users text-blue-500 mr-3 text-xl"></i>
                                        <h3 class="text-xl font-semibold">保存用户凭证</h3>
                                    </div>
                                    <p>实现多系统之间的单点登录凭证，统一用户认证系统。</p>
                                </div>
                            </div>
                        </div>
                        
                        <div class="mt-6 bg-white rounded-xl shadow-md overflow-hidden">
                            <div class="bg-yellow-50 p-4 border-l-4 border-yellow-400">
                                <div class="flex items-start">
                                    <i class="fas fa-lightbulb text-yellow-500 mt-1 mr-3"></i>
                                    <div>
                                        <h4 class="font-medium text-yellow-800">核心价值总结</h4>
                                        <p class="text-yellow-700">减轻数据库的压力，将经常被访问，但更新不频繁的数据，保存在缓存中，这样可以减少对数据库的操作。</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 3: 环境搭建 -->
                    <section id="section3" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">3. 环境搭建</h2>
                        
                        <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <i class="fas fa-server feature-icon mr-3"></i>
                                    <h3 class="text-xl font-semibold">安装步骤</h3>
                                </div>
                                
                                <div class="space-y-4">
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium"># 安装gcc环境</div>
                                        <div class="px-4 py-3 font-mono">yum -y install gcc-c++</div>
                                    </div>
                                    
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium"># 解压redis源码包</div>
                                        <div class="px-4 py-3 font-mono">tar -zxvf redis-3.2.6.tar.gz</div>
                                    </div>
                                    
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium"># 编译redis源码(进入到Redis目录)</div>
                                        <div class="px-4 py-3 font-mono">Make</div>
                                    </div>
                                    
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium"># 安装redis</div>
                                        <div class="px-4 py-3 font-mono">make install PREFIX=/usr/local/redis3 <span class="text-gray-500">-- 指定安装到某个路径下面</span></div>
                                    </div>
                                </div>
                                
                                <div class="mt-6 bg-blue-50 p-4 rounded-lg border-l-4 border-blue-500">
                                    <p class="text-blue-800"><i class="fas fa-info-circle mr-2"></i>Redis默认是使用前台进程启动，所以要操作Redis需要重新再开一个窗口</p>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 4: 服务启动 -->
                    <section id="section4" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">4. 服务启动</h2>
                        
                        <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <i class="fas fa-power-off feature-icon mr-3"></i>
                                    <h3 class="text-xl font-semibold">启动方式</h3>
                                </div>
                                
                                <div class="space-y-6">
                                    <div>
                                        <h4 class="font-medium text-red-600 mb-2">1. 默认方式启动（非守护线程启动）</h4>
                                        <div class="command mb-3">
                                            <div class="command-title px-4 py-2 font-mono font-medium"># 启动Redis服务</div>
                                            <div class="px-4 py-3 font-mono">bin/redis-server</div>
                                        </div>
                                        <div class="command">
                                            <div class="command-title px-4 py-2 font-mono font-medium"># 客户端连接</div>
                                            <div class="px-4 py-3 font-mono">bin/redis-cli</div>
                                        </div>
                                        <div class="mt-3 bg-yellow-50 p-3 rounded-lg border-l-4 border-yellow-400">
                                            <p class="text-yellow-800 text-sm"><i class="fas fa-exclamation-triangle mr-2"></i>注意：ssh命令窗口关闭则redis-server程序结束，所以不推荐，仅作了解</p>
                                        </div>
                                    </div>
                                    
                                    <div>
                                        <h4 class="font-medium text-red-600 mb-2">2. 按配置文件的方式启动（守护线程的方式启动）</h4>
                                        <div class="space-y-3">
                                            <div class="command">
                                                <div class="command-title px-4 py-2 font-mono font-medium"># 复制配置文件</div>
                                                <div class="px-4 py-3 font-mono">cp redis.conf /usr/local/redis3/bin/</div>
                                            </div>
                                            <div class="command">
                                                <div class="command-title px-4 py-2 font-mono font-medium"># 修改redis.conf，将daemonize由no改为yes</div>
                                                <div class="px-4 py-3 font-mono">vim redis.conf</div>
                                            </div>
                                            <div class="command">
                                                <div class="command-title px-4 py-2 font-mono font-medium"># 启动redis</div>
                                                <div class="px-4 py-3 font-mono">./redis-server redis.conf</div>
                                            </div>
                                            <div class="command">
                                                <div class="command-title px-4 py-2 font-mono font-medium"># 关闭redis</div>
                                                <div class="px-4 py-3 font-mono">./redis-cli shutdown</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 5: Redis客户端 -->
                    <section id="section5" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">5. Redis客户端</h2>
                        
                        <div class="bg-white rounded-xl shadow-md overflow-hidden">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <i class="fas fa-terminal feature-icon mr-3"></i>
                                    <h3 class="text-xl font-semibold">客户端操作</h3>
                                </div>
                                
                                <div class="command mb-6">
                                    <div class="command-title px-4 py-2 font-mono font-medium"># 指定主机和端口连接redis服务端</div>
                                    <div class="px-4 py-3 font-mono">./redis-cli -h 127.0.0.1 -p 6379</div>
                                </div>
                                
                                <div class="bg-blue-50 p-4 rounded-lg border-l-4 border-blue-500">
                                    <p class="text-blue-800"><i class="fas fa-info-circle mr-2"></i>默认不写-h和-p则默认为127.0.0.1,6379</p>
                                    <p class="text-blue-800 mt-2"><i class="fas fa-info-circle mr-2"></i>./bin/redis-cli --raw // 这种进入方式可以显示中文</p>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 6: 解除本地绑定 -->
                    <section id="section6" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">6. 解除本地绑定</h2>
                        
                        <div class="bg-white rounded-xl shadow-md overflow-hidden">
                            <div class="p-6">
                                <div class="bg-red-50 p-4 rounded-lg border-l-4 border-red-500 mb-4">
                                    <p class="text-red-800"><i class="fas fa-exclamation-triangle mr-2"></i>注意：Redis的低版本默认没有设置仅限本机访问，而高版本有设置，所以需要将高版本的本机绑定注释掉</p>
                                </div>
                                
                                <div class="code-block p-4 overflow-x-auto">
                                    <pre class="text-sm">
# 在redis.conf中找到并注释掉下面这行
# bind 127.0.0.1</pre>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 7: 安全加固 -->
                    <section id="section7" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">7. 安全加固</h2>
                        
                        <div class="bg-white rounded-xl shadow-md overflow-hidden">
                            <div class="p-6">
                                <h3 class="text-xl font-semibold mb-4">设置Redis的访问密码</h3>
                                
                                <div class="space-y-4">
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium"># 修改redis.conf，添加或修改以下配置</div>
                                        <div class="px-4 py-3 font-mono">requirepass yourpassword</div>
                                    </div>
                                    
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium"># 客户端连接时验证密码</div>
                                        <div class="px-4 py-3 font-mono">auth yourpassword</div>
                                    </div>
                                    
                                    <div class="bg-green-50 p-4 rounded-lg border-l-4 border-green-500 mt-4">
                                        <p class="text-green-800"><i class="fas fa-check-circle mr-2"></i>修改配置后需要重启Redis服务生效</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 8: Java连接Redis -->
                    <section id="section8" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">8. Java连接Redis</h2>
                        
                        <div class="bg-white rounded-xl shadow-md overflow-hidden">
                            <div class="p-6">
                                <h3 class="text-xl font-semibold mb-4">使用Jedis客户端</h3>
                                
                                <div class="space-y-6">
                                    <div>
                                        <h4 class="font-medium mb-2">Maven依赖</h4>
                                        <div class="code-block p-4 overflow-x-auto">
                                            <pre class="text-sm">
&lt;dependency&gt;
    &lt;groupId&gt;redis.clients&lt;/groupId&gt;
    &lt;artifactId&gt;jedis&lt;/artifactId&gt;
    &lt;version&gt;2.9.0&lt;/version&gt;
&lt;/dependency&gt;</pre>
                                        </div>
                                    </div>
                                    
                                    <div>
                                        <h4 class="font-medium mb-2">基本使用</h4>
                                        <div class="code-block p-4 overflow-x-auto">
                                            <pre class="text-sm">
Jedis jedis = new Jedis("localhost", 6379);
jedis.auth("yourpassword"); // 如果有密码
jedis.set("key", "value");
String value = jedis.get("key");</pre>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 9: Spring操作Redis -->
                    <section id="section9" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">9. Spring操作Redis</h2>
                        
                        <div class="space-y-8">
                            <!-- 9.1 添加依赖 -->
                            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                                <div class="p-6">
                                    <h3 class="text-xl font-semibold mb-4">9.1 添加依赖</h3>
                                    
                                    <div class="code-block p-4 overflow-x-auto">
                                        <pre class="text-sm">
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
    &lt;artifactId&gt;spring-data-redis&lt;/artifactId&gt;
    &lt;version&gt;1.8.8.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
    &lt;version&gt;4.3.8.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;redis.clients&lt;/groupId&gt;
    &lt;artifactId&gt;jedis&lt;/artifactId&gt;
    &lt;version&gt;2.9.0&lt;/version&gt;
&lt;/dependency&gt;</pre>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- 9.2 Redis和Spring整合配置 -->
                            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                                <div class="p-6">
                                    <h3 class="text-xl font-semibold mb-4">9.2 Redis和Spring整合配置</h3>
                                    
                                    <div class="code-block p-4 overflow-x-auto">
                                        <pre class="text-sm">
&lt;!-- 配置redis连接池对象 --&gt;
&lt;bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"&gt;
    &lt;!-- 最大空闲数 --&gt;
    &lt;property name="maxIdle" value="50" /&gt;
    &lt;!-- 最大连接数 --&gt;
    &lt;property name="maxTotal" value="100" /&gt;
    &lt;!-- 最大等待时间 --&gt;
    &lt;property name="maxWaitMillis" value="20000" /&gt;
&lt;/bean&gt;

&lt;!-- 配置redis连接工厂 --&gt;
&lt;bean id="connectionFactory"
      class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"&gt;
    &lt;!-- 连接池配置 --&gt;
    &lt;property name="poolConfig" ref="poolConfig" /&gt;
    &lt;!-- 连接主机 --&gt;
    &lt;property name="hostName" value="192.168.189.137" /&gt;
    &lt;!-- 端口 --&gt;
    &lt;property name="port" value="6379" /&gt;
    &lt;!-- 密码 --&gt;
    &lt;property name="password" value="root" /&gt;
&lt;/bean&gt;

&lt;!-- 配置redis模板对象 --&gt;
&lt;bean class="org.springframework.data.redis.core.RedisTemplate"&gt;
    &lt;!-- 配置连接工厂 --&gt;
    &lt;property name="connectionFactory" ref="connectionFactory" /&gt;
    &lt;!-- 配置Redis key系列化方式为spring --&gt;
    &lt;property name="keySerializer" ref="stringRedisSerializer"&gt;&lt;/property&gt;
    &lt;property name="valueSerializer" ref="stringRedisSerializer"&gt;&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"&gt;&lt;/bean&gt;</pre>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- 9.3 测试 -->
                            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                                <div class="p-6">
                                    <h3 class="text-xl font-semibold mb-4">9.3 测试</h3>
                                    
                                    <div class="code-block p-4 overflow-x-auto">
                                        <pre class="text-sm">
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(value ="classpath:applicationContext.xml")
public class SpringRedisTest {

    @Autowired
    private RedisTemplate redisTemplate;
    
    @Test
    public void testSpringRedis(){
        redisTemplate.opsForValue().set("username","admin");
        System.out.println(redisTemplate.opsForValue().get("username"));
    }
}</pre>
                                    </div>
                                    
                                    <div class="bg-red-50 p-4 rounded-lg border-l-4 border-red-500 mt-4">
                                        <h4 class="font-medium text-red-800 mb-2">问题</h4>
                                        <p class="text-red-700">Java客户端可以正常访问存放进去的key，但是如果从服务器的客户端访问却访问不到。</p>
                                        <p class="text-red-700 mt-2"><strong>原因：</strong>Spring-data-redis提供的模板对象，默认会对我们的信息进行序列化(JDK的方式)，所以存放进去的key和value都将会有所变化。</p>
                                        <p class="text-red-700 mt-2"><strong>解决方案：</strong>利用字符串的方式序列化key和value</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 12: 事务管理 -->
                    <section id="section12" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">12. 事务管理</h2>
                        
                        <div class="bg-white rounded-xl shadow-md overflow-hidden">
                            <div class="p-6">
                                <h3 class="text-xl font-semibold mb-4">Redis事务特点</h3>
                                
                                <div class="space-y-4">
                                    <p>redis的事务是使用multi-exec的命令组合，使用它可以提供两个重要保证：</p>
                                    
                                    <ol class="list-decimal pl-5 space-y-2">
                                        <li>事务是一个被隔离的操作，事务中的方法都会被redis进行序列化并按顺序执行，事务在执行的过程中不会被其他客户端的发出的命令所打断。</li>
                                        <li>事务是一个原子性操作，它要么全部执行、要么全部不执行。</li>
                                    </ol>
                                    
                                    <p>multi到exec命令之间的Redis命令将采取进入队列的形式，直至exec命令的出现，才会一次性发送队列的命令去执行。</p>
                                </div>
                                
                                <h3 class="text-xl font-semibold mt-8 mb-4">基本事务的命令</h3>
                                
                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium">Multi</div>
                                        <div class="px-4 py-3">开启事务，之后的命令就会进入队列，而不是马上执行</div>
                                    </div>
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium">Exec</div>
                                        <div class="px-4 py-3">提交事务，如果被监听的键没有被修改，则采用提交命令，否则就执行回滚命令</div>
                                    </div>
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium">Discard</div>
                                        <div class="px-4 py-3">回滚事务</div>
                                    </div>
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium">watch key1 [key2]...</div>
                                        <div class="px-4 py-3">监听某些键，当被监听的键在提交事务前被修改，则事务会回滚 （基于乐观锁机制）</div>
                                    </div>
                                    <div class="command">
                                        <div class="command-title px-4 py-2 font-mono font-medium">unwatch</div>
                                        <div class="px-4 py-3">取消监听</div>
                                    </div>
                                </div>
                                
                                <h3 class="text-xl font-semibold mt-8 mb-4">SpringBoot操作Redis事务</h3>
                                
                                <div class="code-block p-4 overflow-x-auto mb-4">
                                    <pre class="text-sm">
@Test
public void testRedisTransaction(){
    try{
        // 1.开启事务
        redisTemplate.multi();

        // 2.操作redis
        redisTemplate.opsForValue().set("name","admin");
        redisTemplate.opsForValue().set("age",12);

        // 3.事务提交
        redisTemplate.exec();
    }catch (Exception e){
        // 4.出现异常事务回滚
        redisTemplate.discard();
        e.printStackTrace();
    }
}</pre>
                                </div>
                                
                                <div class="bg-yellow-50 p-4 rounded-lg border-l-4 border-yellow-400">
                                    <p class="text-yellow-800"><i class="fas fa-exclamation-triangle mr-2"></i>该程序执行完后会出现异常：事务回滚的时候没有开启事务，就是事务开启和事务回滚没有在一个redis连接里面进行。</p>
                                </div>
                                
                                <div class="code-block p-4 overflow-x-auto mt-4">
                                    <pre class="text-sm">
@Test
public void testRedisTransaction2(){
    redisTemplate.execute(new SessionCallback() {
        @Nullable // 标识参数可以为空
        @Override
        public Object execute(RedisOperations redisOperations) throws DataAccessException {
            try{
                // 1.开启事务
                redisTemplate.multi();

                // 2.操作redis
                redisTemplate.opsForValue().set("name","admin");
                redisTemplate.opsForValue().set("age",12);

                // 3.事务提交
                List list = redisTemplate.exec();
                System.out.println(list);
            }catch (Exception e){
                // 4.出现异常事务回滚
                redisTemplate.discard();
                e.printStackTrace();
            }
            return null;
        }
    });
}</pre>
                                </div>
                                
                                <div class="bg-blue-50 p-4 rounded-lg border-l-4 border-blue-500 mt-4">
                                    <p class="text-blue-800"><i class="fas fa-info-circle mr-2"></i>用execte这个方法操作Redis，就可以保证在匿名类中的所有的操作用的是同一个Redis连接对象。</p>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 17: 持久化机制 -->
                    <section id="section17" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">17. 持久化机制</h2>
                        
                        <div class="bg-white rounded-xl shadow-md overflow-hidden">
                            <div class="p-6">
                                <p class="mb-4">Redis会定期的把内存中的数据持久化到硬盘上，当reids服务关闭后，重启Redis会自动把硬盘的数据恢复到内存中继续使用。可以用shutdown命令关闭Redis服务来进行测试。</p>
                                
                                <h3 class="text-xl font-semibold mt-8 mb-4">Redis两种持久化方式</h3>
                                
                                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
                                    <div class="bg-white border border-gray-200 rounded-lg p-6 shadow-sm">
                                        <h4 class="font-bold text-lg mb-3 text-blue-600">RDB (快照,默认的方式)</h4>
                                        <p>记录当前Reids一瞬间的内存结构，以文件的形式保存的硬盘上。</p>
                                        <div class="mt-4">
                                            <h5 class="font-medium mb-2">快照相关命令：</h5>
                                            <ul class="list-disc pl-5 space-y-1">
                                                <li><strong>Save:</strong> 手动进行快照，这个过程是前台快照，在执行的快照的的过程中，redis是拒绝写命令的。</li>
                                                <li><strong>bgsave:</strong> 手动进行快照，这个过程是后台快照，Redis会启动一个新的线程执行快照，当前线程是接收执行写命令的(它是把写的命令放到缓存中)</li>
                                            </ul>
                                        </div>
                                    </div>
                                    
                                    <div class="bg-white border border-gray-200 rounded-lg p-6 shadow-sm">
                                        <h4 class="font-bold text-lg mb-3 text-green-600">AOF (只追加文件)</h4>
                                        <p>AOF把服务器执行的所有写(增删改)的命令记录在一个文件中,并在服务器启动时,通过重新执行这些命令来还原数据集。</p>
                                    </div>
                                </div>
                                
                                <div class="space-y-8">
                                    <div>
                                        <h3 class="text-xl font-semibold mb-4">RDB (Redis DataBase) 配置</h3>
                                        
                                        <div class="code-block p-4 overflow-x-auto">
                                            <pre class="text-sm">
# 配置快照的频率，意思是900s之内有1个数据发送了变化就拍快照。
save 900 1
save 300 10
save 60 10000

# 因为bgsave命令是启动一个新的线程执行快照，当前线程还是接收写命令的，
# 如果新线程在执行快照的过程中出现错误是否停止写命令，默认是yes
stop-writes-on-bgsave-error yes

# dir ./ 快照文件存放的位置
# rdbchecksum yes 回复快照时检查快照的完整性
# dbfilename dump.rdb 快照文件的名称(可以把这个文件发送给别人，启动后缓存就会有的对应的数据)</pre>
                                        </div>
                                    </div>
                                    
                                    <div>
                                        <h3 class="text-xl font-semibold mb-4">AOF (Append Only File) 配置</h3>
                                        
                                        <div class="code-block p-4 overflow-x-auto">
                                            <pre class="text-sm">
appendonly no # 是否开启只追加文件

appendfilename "appendonly.aof" # 只追加文件的名称

# 只追加文件记录评率
# appendfsync always # 每次执行写操作后记录到只追加文件中(绝对安全)
appendfsync everysec # 每秒中记录一次只追加文件(默认值)
# appendfsync no # 不主动记录只追加文件，需要手动记录

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb # 只追加文件的大小，超过64兆新建一个文件记录命令

aof-load-truncated yes # 如果最后一个命令出现文错误，是否丢弃。</pre>
                                        </div>
                                    </div>
                                    
                                    <div class="bg-blue-50 p-4 rounded-lg border-l-4 border-blue-500">
                                        <h4 class="font-medium text-blue-800 mb-2">快照 VS 只追加文件</h4>
                                        <ul class="list-disc pl-5 space-y-1 text-blue-700">
                                            <li><strong>快照:</strong> 记录和回复的速度快，数据的安全性不高(因为他是按照时间来记录的)</li>
                                            <li><strong>只追加文件:</strong> 记录和恢复的速度慢(命令一旦很多久执行慢)，数据安全性高(因为最多只丢失1s的数据)</li>
                                            <li>如果Redis只是作为缓存服务器话，快照和只追加文件都可以关闭，这样可以大大的提高Redis读写性能</li>
                                            <li>如果对数据要求安全性很高，则两个都可以开启</li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>

                    <!-- Section 18: 内存管理 -->
                    <section id="section18" class="mb-16">
                        <h2 class="text-3xl font-bold mb-6 section-title">18. 内存管理</h2>
                        
                        <div class="bg-white rounded-xl shadow-md overflow-hidden">
                            <div class="p-6">
                                <h3 class="text-xl font-semibold mb-4">回收策略</h3>
                                
                                <div class="code-block p-4 overflow-x-auto mb-6">
                                    <pre class="text-sm">
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key according to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
#
# The default is:
#
# maxmemory-policy noeviction</pre>
                                </div>
                                
                                <div class="bg-yellow-50 p-4 rounded-lg border-l-4 border-yellow-400 mb-6">
                                    <p class="text-yellow-800"><i class="fas fa-exclamation-circle mr-2"></i><strong>注意：</strong>为了提高垃圾回收的策略，LRU和TTL算法都不是精确的算法，而是一个近似的算法。就是他会根据探测样本的数量设置，来进行探测，然后根据探测到这几个进行淘汰。</p>
                                </div>
                                
                                <div class="code-block p-4 overflow-x-auto">
                                    <pre class="text-sm">
# LRU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can tune it for speed or
# accuracy. For default Redis will check five keys and pick the one that was
# used less recently, you can change the sample size using the following
# configuration directive.
#
# The default of 5 produces good enough results. 10 Approximates very closely
# true LRU but costs more CPU. 3 is faster but not very accurate.
#
# maxmemory-samples 5</pre>
                                </div>
                                
                                <div class="mt-6 bg-blue-50 p-4 rounded-lg border-l-4 border-blue-500">
                                    <h4 class="font-medium text-blue-800 mb-2">总结：</h4>
                                    <ul class="list-disc pl-5 space-y-1 text-blue-700">
                                        <li>默认的回收策略:默认不回收</li>
                                        <li>设置回收的算法，LRU,random,TTL</li>
                                        <li>算法不是精确的，而是采样的方式，可以设置采样的个数，默认是5个</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
```